package vsy.buzzwordbingo.controller;

import java.security.Principal;

import javax.servlet.http.HttpServletRequest;

import org.apache.tiles.AttributeContext;
import org.apache.tiles.context.TilesRequestContext;
import org.apache.tiles.preparer.ViewPreparer;
import org.springframework.stereotype.Controller;

import vsy.buzzwordbingo.util.ViewPreparerUtil;

@Controller("menuController")
public class MenuController implements ViewPreparer {

	@Override
	public void execute(TilesRequestContext tilesContext,
			AttributeContext attributeContext) {
		HttpServletRequest request = ViewPreparerUtil
				.getHttpServletRequest(tilesContext);
		if (request != null) {
			Principal principal = request.getUserPrincipal();
			if (principal != null && principal.getName() != null) {
				tilesContext.getRequestScope().put("playerName",
						principal.getName());
			}
		}
	}

}
